package cre.sample.test.gc.oom;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 方法区存放类的相关信息
 * 这里产生大量的类去填充方法区
 * VM Args: -XX:PermSize=10M -XX:MaxPermSize=10M
 * Created by CreGu on 2016/5/24.
 */
public class JavaMethodAreaOOM {

    public static void main(String[] args) {
//        jdk6
        while (true) {
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(OOMObject.class);
            enhancer.setUseCache(false);

            enhancer.setCallback(new MethodInterceptor() {
                @Override
                public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                    return methodProxy.invokeSuper(o, objects);
                }
            });
            enhancer.create();
        }
    }

    static class OOMObject {
    }

}
